package club.xyes.zkh.ecommerce.service.adapter.impl;

import club.xyes.zkh.ecommerce.commons.dto.ConsumptionOverview;
import club.xyes.zkh.ecommerce.commons.entity.Shop;
import club.xyes.zkh.ecommerce.commons.entity.TransactionLog;
import club.xyes.zkh.ecommerce.commons.entity.User;
import club.xyes.zkh.ecommerce.dao.mapper.TransactionLogMapper;
import club.xyes.zkh.ecommerce.service.adapter.TransactionLogSingleDependencyMapperAdapter;
import club.xyes.zkh.ecommerce.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Create by 郭文梁 2019/4/22 0022 09:58
 * TransactionLogSingleDependencyMapperAdapterImpl
 * 交易记录单依赖Mapper适配器
 *
 * @author 郭文梁
 * @data 2019/4/22 0022
 */
@Service("transactionLogSingleDependencyMapperAdapterImpl")
public class TransactionLogSingleDependencyMapperAdapterImpl extends BaseServiceImpl<TransactionLog> implements TransactionLogSingleDependencyMapperAdapter {
    private final TransactionLogMapper mapper;

    @Autowired
    public TransactionLogSingleDependencyMapperAdapterImpl(TransactionLogMapper mapper) {
        super(mapper);
        this.mapper = mapper;
    }

    @Override
    public TransactionLog findByTradeNo(String tradeNo) {
        TransactionLog query = new TransactionLog();
        query.setTradeNo(tradeNo);
        return findOneByQuery(query);
    }

    @Override
    public ConsumptionOverview getConsumptionOverview(Shop shop, User user) {
        Integer shopId = shop.getId();
        Integer userId = user.getId();
        return mapper.overviewByUserAndShop(userId, shopId);
    }
}
